package com.gk.study.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.math.BigDecimal;

@Mapper
public interface TeacherMapper {
    @Select("SELECT COALESCE(SUM(o.total_amount), 0) " +
            "FROM b_order o " +
            "WHERE o.thing_id = (SELECT id FROM b_thing WHERE user_id = #{userId}) " +
            "AND o.id IN (" +
            "   SELECT c.order_id FROM b_course c " +
            "   WHERE c.teacher_id = (SELECT id FROM b_thing WHERE user_id = #{userId}) " +
            "   AND c.status = 'COMPLETED'" +
            ")")
    BigDecimal selectTotalIncomeByUserId(@Param("userId") Long userId);
}